import java.util.ArrayList;


public class Simulator {
	
	ArrayList<Station> registeredStations;
	ArrayList<Machine> registeredMachines;
	
	static int serverPort = 9000;
		
	public static void main(String[] args){
			
			Simulator a = new Simulator(serverPort);
		
	}
	
	
	public Simulator(int port){
		
		this.registeredMachines =  new ArrayList<Machine>();
		this.registeredStations = new ArrayList<Station>();
		
		System.out.println("Simulator is running...");
		
		new ServerThread(port, this).start();
		
		new Simulate(this).start();
	}
	
	/** Register new machine **/
	public void addMachine(Machine a){
		
		this.registeredMachines.add(a);
	}
	
	public void removeMachine(int id){
		
		Machine b = null;
		
		for(Machine a : this.registeredMachines){
			
			if(a.getID() == id)
				b = a;
			
		}
		
		b.kill();
		
		this.registeredMachines.remove(b);
	}
	
	
	public Machine findMachine(int id){
		
		for(Machine a : this.registeredMachines)
			if(a.getID() == id)
				return a;
		
		return null;
	}
	
	/** Register new Station **/
    public void addStation(Station a){
        
        this.registeredStations.add(a);
    }
    
    public void removeStation(int id){
        
        Station b = null;
        
        for(Station a : this.registeredStations){
            
            if(a.getID() == id)
                b = a;
        }
        
        this.registeredStations.remove(b);
    }
    
    
    public Station findStation(int id){
        
        for(Station a : this.registeredStations)
            if(a.getID() == id)
                return a;
        
        return null;
    }
	
}
